﻿using System.Linq;
using System.Collections.Generic;
using UcAsp.Net.IDAL;
using UcAsp.Net.Model;
namespace UcAsp.Net.BLL
{
    public class ArticlesPageBLL
    {
        private static readonly IArticlesPageDAL dal = DALFactory.DataAccess.CreateArticlesPage();
        public ArticlesPage Insert(ArticlesPage model)
        {
            return dal.Insert(model);
        }
        public List<ArticlesPage> GetArticlesPageByArticlesID(int artclesid)
        {
            List<ArticlesPage> list = dal.GetArticlesPageByArticlesID(artclesid);
            ArticlesPage page = list.FirstOrDefault(o => o.PageID == 2);
            if (page == null)
            {
                foreach (ArticlesPage art in list)
                {
                    art.PageID = art.PageID - 1;
                    Update(art);
                }

            }
            return list;
        }
        public ArticlesPage GetArticlesPageByPageID(int artclesid, int pageid)
        {
            return dal.GetArticlesPageByPageID(artclesid, pageid);
        }
        public ArticlesPage GetArticlesPageByID(int id)
        {
            return dal.GetArticlesPageByID(id);
        }
        public ArticlesPage Update(ArticlesPage model)
        {
            return dal.Update(model);
        }
        public void Delete(int id)
        {
            dal.Delete(id);
        }
    }
}